Skip to main content
Version: 16.8.2

libraries

os_info

os_info = {
"Linux": {
"archive_manager": {
"file_name": "libglasswall.archi ...

Library

class Library()

A Glasswall library.

__init__

def __init__(library_path: str)

load_library

def load_library(library_path: str)

Success

class Success(WordSearchSuccess)

WordSearch success code 1.

success_codes

success_codes = {
1: Success,
}

UnknownErrorCode

class UnknownErrorCode(WordSearchError)

Unknown error code.

Fail

class Fail(WordSearchError)

WordSearch error code 0.

DisallowedItemFound

class DisallowedItemFound(WordSearchError)

WordSearch error code -1024. Item disallowed by policy found in file.

RequiredItemNotFound

class RequiredItemNotFound(WordSearchError)

WordSearch error code -1025. Item required by policy not found in file.

IllegalActionRedact

class IllegalActionRedact(WordSearchError)

WordSearch error code -1026. Redact action specified but filetype doesn't support redaction.

IllegalActionRequire

class IllegalActionRequire(WordSearchError)

WordSearch error code -1027. Require action specified but filetype doesn't support redaction.

IllegalActionNoRequire

class IllegalActionNoRequire(WordSearchError)

WordSearch error code -1028. Require action not specified but filetype needs one.

FiletypeUnsupported

class FiletypeUnsupported(WordSearchError)

WordSearch error code -1029. Filetype supported by Editor but not by Word Search.

error_codes

error_codes = {
0: Fail,
-1024: DisallowedItemFound,
-1025: RequiredItemNotFound,
-1 ...

WordSearchError

class WordSearchError(Exception)

Base class for all WordSearch errors.

WordSearchSuccess

class WordSearchSuccess()

Base class for all WordSearch successes.

WordSearch

class WordSearch(Library)

A high level Python wrapper for Glasswall WordSearch.

__init__

def __init__(library_path: str)

version

def version()

Returns the Glasswall library version.

Returns:

  • version str - The Glasswall library version.

redact_file

@glasswall.utils.deprecated_alias(xml_config="content_management_policy")
def redact_file(input_file: Union[str, bytes, bytearray, io.BytesIO],
content_management_policy: Union[str, bytes, bytearray,
io.BytesIO],
output_file: Union[None, str] = None,
output_report: Union[None, str] = None,
homoglyphs: Union[None, str, bytes, bytearray,
io.BytesIO] = None,
raise_unsupported: bool = True)

Redacts text from input_file using the given content_management_policy and homoglyphs file, optionally writing the redacted file and report to the paths specified by output_file and output_report.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes. content_management_policy (Union[str, bytes, bytearray, io.BytesIO)]): The content management policy to apply.
  • output_file Union[None, str], optional - Default None. If str, write output_file to that path.
  • output_report Union[None, str], optional - Default None. If str, write output_file to that path. homoglyphs (Union[None, str, bytes, bytearray, io.BytesIO)], optional): Default None. The homoglyphs json file path or bytes.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • gw_return_object glasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

redact_directory

@glasswall.utils.deprecated_alias(xml_config="content_management_policy")
def redact_directory(input_directory: str,
content_management_policy: Union[
str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.policy.Policy],
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
homoglyphs: Union[None, str, bytes, bytearray,
io.BytesIO] = None,
raise_unsupported: bool = True)

Redacts all files in a directory and it's subdirectories using the given content_management_policy and homoglyphs file. The redacted files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to redact.
  • output_directory str - The output directory where the redacted files will be written.
  • output_report_directory Optional[str], optional - Default None. If str, the output directory where analysis reports for each redacted file will be written. content_management_policy (Union[str, bytes, bytearray, io.BytesIO)]): The content management policy to apply. homoglyphs (Union[None, str, bytes, bytearray, io.BytesIO)], optional): Default None. The homoglyphs file path, str, or bytes.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • redacted_files_dict dict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

Success

class Success(RebuildSuccess)

Rebuild success code 1. This value indicates the operation completed successfully. Any required Analysis or Protection was carried out and completed.

success_codes

success_codes = {
1: Success,
}

UnknownErrorCode

class UnknownErrorCode(RebuildError)

Unknown error code.

Error

class Error(RebuildError)

Rebuild error code 0. This value indicates that the document was non-conformant in some way, but any requested output files were written.

SuccessDocumentWriteFailure

class SuccessDocumentWriteFailure(RebuildError)

Rebuild error code -1. This value indicates that the document was managed successfully, but a failure occured when writing the managed version of the document to file.

SuccessAnalysisWriteFailure

class SuccessAnalysisWriteFailure(RebuildError)

Rebuild error code -2. This value indicates that the document was analysed successfully, but a failure occured when writing the analysis of the document to file.

ErrorAnalysisWriteFailure

class ErrorAnalysisWriteFailure(RebuildError)

Rebuild error code -3. This value indicates that the document was non-conformant in some way, and a failure occured when writing the analysis of the document to file.

SuccessReportWriteFailure

class SuccessReportWriteFailure(RebuildError)

Rebuild error code -4. This value indicates that the document was processed successfully, but that a failure occured when writing the processing report to file.

SuccessDocumentReportWriteFailure

class SuccessDocumentReportWriteFailure(RebuildError)

Rebuild error code -5. This value indicates that the document was managed successfully, but a failure occured when writing both the managed version of the document and the processing report to file.

ErrorReportWriteFailure

class ErrorReportWriteFailure(RebuildError)

Rebuild error code -6. This value indicates that the document was non-conformant in some way, and that a failure occured when writing the processing report to file.

SuccessAnalysisReportWriteFailure

class SuccessAnalysisReportWriteFailure(RebuildError)

Rebuild error code -7. This value indicates that the document was analysed successfully, but a failure occured when writing both the analysis of the document and the processing report to file.

ErrorAnalysisReportWriteFailure

class ErrorAnalysisReportWriteFailure(RebuildError)

Rebuild error code -8. This value indicates that the document was non-conformant in some way, but a failure occured when writing both the analysis of the document and the processing report to file.

InternalError

class InternalError(RebuildError)

Rebuild error code -9. This value indicates an uncategorised error

SuccessDocumentAnalysisReportWriteFailure

class SuccessDocumentAnalysisReportWriteFailure(RebuildError)

Rebuild error code -10. This value indicates that the document was analysed successfully, but failures occured when writing the document, the analysis of the document and the processing report to file (AMP mode).

SuccessDocumentAnalysisWriteFailure

class SuccessDocumentAnalysisWriteFailure(RebuildError)

Rebuild error code -11. This value indicates that the document was analysed successfully, but failures occured when writing the document and the analysis of the document to file (AMP mode).

SuccessExportWriteFailure

class SuccessExportWriteFailure(RebuildError)

Rebuild error code -12. This value indicates that the document was exported successfully, but failures occured when writing the archive package. (Export mode)

ErrorExportWriteFailure

class ErrorExportWriteFailure(RebuildError)

Rebuild error code -13. This value indicates that the document was non-conformant in some way, and failures occured when writing the archive package. (Export mode)

ErrorRejectedFileFailure

class ErrorRejectedFileFailure(RebuildError)

Rebuild error code -16. This value indicates that the document was processed successfully but rejected based on policy.

error_codes

error_codes = {
0: Error,
-1: SuccessDocumentWriteFailure,
-2: SuccessAnalysisWriteFailu ...

RebuildError

class RebuildError(Exception)

Base class for all Glasswall Rebuild errors.

RebuildSuccess

class RebuildSuccess()

Base class for all Glasswall Rebuild successes.

Rebuild

class Rebuild(Library)

A high level Python wrapper for Glasswall Rebuild / Classic.

__init__

def __init__(library_path: str)

validate_licence

def validate_licence()

Validates the licence of the library by attempting to call protect_file on a known supported file.

Raises:

  • RebuildError - If the licence could not be validated.

version

def version()

Returns the Glasswall library version.

Returns:

  • version str - The Glasswall library version.

determine_file_type

def determine_file_type(input_file: Union[str, bytes, bytearray, io.BytesIO],
as_string: bool = False,
raise_unsupported: bool = True)

Returns an int representing the file type / file format of a file.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file, can be a local path.
  • as_string bool, optional - Return file type as string, eg: "bmp" instead of: 29. Defaults to False.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_type Union[int, str] - The file format.

get_content_management_policy

def get_content_management_policy()

Gets the current content management configuration.

Returns:

  • xml_string str - The XML string of the current content management configuration.

set_content_management_policy

def set_content_management_policy(input_file: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None)

Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.

Arguments:

  • input_file Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.

Returns:

  • status int - The result of the Glasswall API call.

protect_file

def protect_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Protects a file using the current content management configuration, returning the file bytes. The protected file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the protected file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The protected file bytes.

protect_directory

def protect_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory in protect mode using the given content management policy. The protected files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to protect.
  • output_directory Union[None, str] - The output directory where the protected file will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • protected_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

analyse_file

def analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses a file, returning the analysis bytes. The analysis is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the analysis file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The analysis file bytes.

analyse_directory

def analyse_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses all files in a directory and its subdirectories. The analysis files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to analyse.
  • output_directory Union[None, str] - The output directory where the analysis files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • analysis_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

export_file

def export_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Export a file, returning the .zip file bytes. The .zip file is written to output_file.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the .zip file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The exported .zip file.

export_directory

def export_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Exports all files in a directory and its subdirectories. The export files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to export.
  • output_directory Union[None, str] - The output directory where the export files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • export_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

import_file

def import_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Union[None, str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Import a .zip file, constructs a file from the .zip file and returns the file bytes. The file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The .zip input file path or bytes.
  • output_file Union[None, str], optional - The output file path where the constructed file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The imported file bytes.

import_directory

def import_directory(
input_directory: str,
output_directory: Union[None, str],
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Imports all files in a directory and its subdirectories. Files are expected as .zip but this is not forced. The constructed files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to import.
  • output_directory Union[None, str] - The output directory where the constructed files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • import_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

GWFileErrorMsg

def GWFileErrorMsg()

Retrieve the Glasswall Process error message.

Returns:

  • error_message str - The Glasswall Process error message.

ArchiveManager

class ArchiveManager(Library)

A high level Python wrapper for Glasswall Archive Manager.

__init__

def __init__(library_path)

version

def version()

Returns the Glasswall library version.

Returns:

  • version str - The Glasswall library version.

release

def release()

Releases any resources held by the Glasswall Archive Manager library.

supported_archives

@property
@functools.lru_cache()
def supported_archives()

Returns a list of supported archive file formats.

is_supported_archive

@functools.lru_cache()
def is_supported_archive(archive_type: str)

Returns True if the archive type (e.g. 7z) is supported.

list_archive_paths

def list_archive_paths(directory: str,
recursive: bool = True,
absolute: bool = True,
followlinks: bool = True)

Returns a list of file paths of supported archives in a directory and all of its subdirectories.

determine_file_type

def determine_file_type(input_file: str,
as_string: bool = False,
raise_unsupported: bool = True)

Returns an int representing the file type of an archive.

Arguments:

input_file (str) The input file path.

  • as_string bool, optional - Return file type as string, eg: "xz" instead of: 262. Defaults to False.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_type Union[int, str] - The file format.

analyse_archive

def analyse_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.
  • output_file Optional[str], optional - Default None. If str, write the archive to the output_file path.
  • output_report Optional[str], optional - Default None. If str, write the analysis report to the output_report path.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • gw_return_object glasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)

analyse_directory

def analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Calls analyse_archive on each file in input_directory using the given content management configuration. The resulting archives and analysis reports are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing archives to analyse.
  • output_directory Optional[str], optional - Default None. If str, the output directory where the archives containing analysis reports of each file will be written.
  • output_report_directory Optional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • analysed_archives_dict dict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

protect_archive

def protect_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Extracts the input_file archive and processes each file within the archive using the Glasswall engine. Repackages all files regenerated by the Glasswall engine into a new archive, optionally writing the new archive and report to the paths specified by output_file and output_report.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.
  • output_file Optional[str], optional - Default None. If str, write the archive to the output_file path.
  • output_report Optional[str], optional - Default None. If str, write the analysis report to the output_report path.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • gw_return_object glasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)

protect_directory

def protect_directory(
input_directory: str,
output_directory: Optional[str] = None,
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Calls protect_archive on each file in input_directory using the given content management configuration. The resulting archives are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing archives to protect.
  • output_directory Optional[str], optional - Default None. If str, the output directory where the archives will be written.
  • output_report_directory Optional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • protected_archives_dict dict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

file_to_file_unpack

def file_to_file_unpack(input_file: str,
output_directory: str,
raise_unsupported: bool = True)

file_to_file_pack

def file_to_file_pack(input_directory: str,
output_directory: str,
file_type: Optional[str] = None,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True)

unpack

def unpack(input_file: str,
output_directory: str,
recursive: bool = True,
include_file_type: bool = False,
raise_unsupported: bool = True,
delete_origin: bool = False)

Unpack an archive, maintaining directory structure. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".

Arguments:

  • input_file str - The archive file path
  • output_directory str - The output directory where the archive will be unpacked to a new directory.
  • recursive bool, optional - Default True. Recursively unpack all nested archives.
  • include_file_type bool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
  • delete_origin bool, optional - Default False. Delete input_file after unpacking to output_directory.

unpack_directory

def unpack_directory(input_directory: str,
output_directory: str,
recursive: bool = True,
include_file_type: Optional[bool] = False,
raise_unsupported: bool = True,
delete_origin: bool = False)

Unpack a directory of archives, maintaining directory structure.

Arguments:

  • input_directory str - The input directory containing archives to unpack.
  • output_directory str - The output directory where archives will be unpacked to a new directory.
  • recursive bool, optional - Default True. Recursively unpack all nested archives.
  • include_file_type bool, optional - Default False. Include the archive format in the directory name. Useful when there are multiple same-named archives of different formats.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
  • delete_origin bool, optional - Default False. Delete input_file after unpacking to output_directory.

pack_directory

def pack_directory(input_directory: str,
output_directory: str,
file_type: str,
add_extension: Optional[bool] = True,
raise_unsupported: Optional[bool] = True,
delete_origin: Optional[bool] = False)

Pack a directory. Supported archive formats are: "7z", "bz2", "gz", "rar", "tar", "xz", "zip".

Arguments:

  • input_directory str - The input directory containing files to archive.
  • output_directory str - The output directory to store the created archive.
  • file_type str - The archive file type.
  • add_extension bool, optional - Default: True. Archive file type extension to result file.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.
  • delete_origin bool, optional - Default False. Delete input_directory after packing to output_directory.

export_archive

def export_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Exports an archive using the Glasswall engine.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.
  • output_file Optional[str], optional - Default None. If str, write the archive to the output_file path.
  • output_report Optional[str], optional - Default None. If str, write the analysis report to the output_report path.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • gw_return_object glasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)

export_directory

def export_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
raise_unsupported: bool = True)

Calls export_archive on each file in input_directory. The exported archives are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing archives to export.
  • output_directory Optional[str], optional - Default None. If str, the output directory where the archives will be written.
  • output_report_directory Optional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • exported_archives_dict dict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

import_archive

def import_archive(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: Optional[bool] = True)

Imports an archive using the Glasswall engine.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The archive file path or bytes.
  • output_file Optional[str], optional - Default None. If str, write the archive to the output_file path.
  • output_report Optional[str], optional - Default None. If str, write the analysis report to the output_report path.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • include_analysis_report Optional[bool], optional - Default False. If True, write the analysis report into the imported archive.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • gw_return_object glasswall.GwReturnObj - An instance of class glasswall.GwReturnObj containing attributes including: "status" (int), "output_file" (bytes), "output_report" (bytes)

import_directory

def import_directory(
input_directory: str,
output_directory: Optional[str],
output_report_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
glasswall.content_management.policies.ArchiveManager] = None,
include_analysis_report: Optional[bool] = False,
raise_unsupported: bool = True)

Calls import_archive on each file in input_directory. The imported archives are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing archives to import.
  • output_directory Optional[str], optional - Default None. If str, the output directory where the archives will be written.
  • output_report_directory Optional[str], optional - Default None. If str, the output directory where xml reports for each archive will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.ArchiveManager], optional - The content management policy to apply.
  • include_analysis_report Optional[bool], optional - Default False. If True, write the analysis report into the imported archive.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • imported_archives_dict dict - A dictionary of file paths relative to input_directory, and glasswall.GwReturnObj with attributes: "status" (int), "output_file" (bytes), "output_report" (bytes)

Success

class Success(ArchiveManagerSuccess)

ArchiveManager success code 1.

success_codes

success_codes = {
1: Success,
}

UnknownErrorCode

class UnknownErrorCode(ArchiveManagerError)

Unknown error code.

Fail

class Fail(ArchiveManagerError)

ArchiveManager error code 0.

error_codes

error_codes = {
0: Fail,
}

ArchiveManagerError

class ArchiveManagerError(Exception)

Base class for all Glasswall ArchiveManager errors.

ArchiveManagerSuccess

class ArchiveManagerSuccess()

Base class for all Glasswall ArchiveManager successes.

OK

class OK(EditorSuccess)

Editor success code 0.

OKWithCleaning

class OKWithCleaning(EditorSuccess)

Editor success code 1.

success_codes

success_codes = {
0: OK,
1: OKWithCleaning,
}

UnknownErrorCode

class UnknownErrorCode(EditorError)

Unknown error code.

GeneralFail

class GeneralFail(EditorError)

Editor error code -1.

UnexpectedEndOfFile

class UnexpectedEndOfFile(EditorError)

Editor error code -2.

LicenceExpired

class LicenceExpired(EditorError)

Editor error code -3.

LicenseExpired

LicenseExpired = LicenceExpired

alias <= 0.2.42

IncorrectSessionSetup

class IncorrectSessionSetup(EditorError)

Editor error code -4.

IncorrectPolicySetup

class IncorrectPolicySetup(EditorError)

Editor error code -5.

UnableToLoadInput

class UnableToLoadInput(EditorError)

Editor error code -6.

FileTypeUnknown

class FileTypeUnknown(EditorError)

Editor error code -7.

UnknownSessionID

class UnknownSessionID(EditorError)

Editor error code -8.

ArgumentError

class ArgumentError(EditorError)

Editor error code -9.

UnableToLoadImport

class UnableToLoadImport(EditorError)

Editor error code -10.

CameraDidNotInitialise

class CameraDidNotInitialise(EditorError)

Editor error code -11.

NoCamerasConnected

class NoCamerasConnected(EditorError)

Editor error code -12.

EngineeringOnlyGoesToFile

class EngineeringOnlyGoesToFile(EditorError)

Editor error code -13.

UnableToWriteOutput

class UnableToWriteOutput(EditorError)

Editor error code -14

UnableToWriteExport

class UnableToWriteExport(EditorError)

Editor error code -15

FileRejected

class FileRejected(EditorError)

Editor error code -16

UnableToWriteExportTextDump

class UnableToWriteExportTextDump(EditorError)

Editor error code -17

UnableToWriteAnalysisReport

class UnableToWriteAnalysisReport(EditorError)

Editor error code -18

InputTooLarge

class InputTooLarge(EditorError)

Editor error code -19

InputZeroBytes

class InputZeroBytes(EditorError)

Editor error code -20

error_codes

error_codes = {
-1: GeneralFail,
-2: UnexpectedEndOfFile,
-3: LicenseExpired,
-4: In ...

Editor

class Editor(Library)

A high level Python wrapper for Glasswall Editor / Core2.

__init__

def __init__(library_path: str,
licence: Union[str, bytes, bytearray, io.BytesIO] = None)

Initialise the Editor instance.

Arguments:

  • library_path str - The file or directory path to the Editor library.
  • licence str, bytes, bytearray, or io.BytesIO, optional - The licence file content or path. This can be:
    • A string representing the file path to the licence.
    • A bytes or bytearray object containing the licence data.
    • An io.BytesIO object for in-memory licence data. If not specified, it is assumed that the licence file is located in the same directory as the library_path.

validate_licence

def validate_licence()

Validates the licence of the library by checking the licence details.

Raises:

  • LicenceExpired - If the licence has expired or could not be validated.

version

def version()

Returns the Glasswall library version.

Returns:

  • version str - The Glasswall library version.

open_session

def open_session()

Open a new Glasswall session.

Returns:

  • session int - An incrementing integer repsenting the current session.

close_session

def close_session(session: int) -> int

Close the Glasswall session. All resources allocated by the session will be destroyed.

Arguments:

  • session int - The session to close.

Returns:

  • status int - The status code of the function call.

new_session

@contextmanager
def new_session()

Context manager. Opens a new session on entry and closes the session on exit.

run_session

def run_session(session)

Runs the Glasswall session and begins processing of a file.

Arguments:

  • session int - The session to run.

Returns:

  • status int - The status code of the function call.

determine_file_type

def determine_file_type(input_file: Union[str, bytes, bytearray, io.BytesIO],
as_string: bool = False,
raise_unsupported: bool = True) -> Union[int, str]

Determine the file type of a given input file, either as an integer identifier or a string.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file to analyse. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.
  • as_string bool, optional - Return file type as string, eg: "bmp" instead of: 29. Defaults to False.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_type Union[int, str] - The file type.

get_content_management_policy

def get_content_management_policy(session: int)

Returns the content management configuration for a given session.

Arguments:

  • session int - The session integer.

Returns:

  • xml_string str - The XML string of the current content management configuration.

set_content_management_policy

def set_content_management_policy(
session: int,
input_file: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
policy_format=0)

Sets the content management policy configuration. If input_file is None then default settings (sanitise) are applied.

Arguments:

  • session int - The session integer.
  • input_file Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • policy_format int - The format of the content management policy. 0=XML.

Returns:

  • result (glasswall.GwReturnObj): Depending on the input 'input_file':

  • If input_file is a str file path:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'policy_format', 'status'.

  • If input_file is a file in memory:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'policy_format', 'status'.

register_input

def register_input(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])

Register an input file or bytes for the given session.

Arguments:

  • session int - The session integer.
  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.

Returns:

  • result (glasswall.GwReturnObj): Depending on the input 'input_file':

  • If input_file is a str file path:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'status'.

  • If input_file is a file in memory:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'status'.

register_output

def register_output(session, output_file: Optional[str] = None)

Register an output file for the given session. If output_file is None the file will be returned as 'buffer' and 'buffer_length' attributes.

Arguments:

  • session int - The session integer.
  • output_file Optional[str] - If specified, during run session the file will be written to output_file, otherwise the file will be written to the glasswall.GwReturnObj 'buffer' and 'buffer_length' attributes.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.

register_analysis

def register_analysis(session: int, output_file: Optional[str] = None)

Registers an analysis file for the given session. The analysis file will be created during the session's run_session call.

Arguments:

  • session int - The session integer.
  • output_file Optional[str] - Default None. The file path where the analysis will be written. None returns the analysis as bytes.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attributes 'status', 'session', 'analysis_format'. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size. If output_file is not None (file mode) 'output_file' is included.

protect_file

def protect_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Protects a file using the current content management configuration, returning the file bytes. The protected file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the protected file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The protected file bytes.

protect_directory

def protect_directory(
input_directory: str,
output_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory in protect mode using the given content management policy. The protected files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to protect.
  • output_directory Optional[str] - The output directory where the protected file will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • protected_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

analyse_file

def analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses a file, returning the analysis bytes. The analysis is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the analysis file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The analysis file bytes.

analyse_directory

def analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Analyses all files in a directory and its subdirectories. The analysis files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to analyse.
  • output_directory Optional[str] - The output directory where the analysis files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • analysis_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

protect_and_analyse_file

def protect_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Protects and analyses a file in a single session, returning both protected file bytes and analysis report bytes.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the protected file will be written.
  • output_analysis_report Optional[str] - The output file path where the XML analysis report will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

Tuple[Optional[bytes], Optional[bytes]]: A tuple of (protected_file_bytes, analysis_report_bytes).

protect_and_analyse_directory

def protect_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory using protect and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to process.
  • output_directory Optional[str] - The output directory for protected files.
  • analysis_directory Optional[str] - The output directory for XML analysis reports.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • result_dict dict - A dictionary mapping relative file paths to tuples of (protected_file_bytes, analysis_report_bytes).

register_export

def register_export(session: int, output_file: Optional[str] = None)

Registers a file to be exported for the given session. The export file will be created during the session's run_session call.

Arguments:

  • session int - The session integer.
  • output_file Optional[str] - Default None. The file path where the export will be written. None exports the file in memory.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call and 'session', the session integer. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.

export_file

def export_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Export a file, returning the .zip file bytes. The .zip file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the .zip file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The exported .zip file.

export_directory

def export_directory(
input_directory: str,
output_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Exports all files in a directory and its subdirectories. The export files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to export.
  • output_directory Optional[str] - The output directory where the export files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • export_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

export_and_analyse_file

def export_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Exports and analyses a file in a single session, returning both exported .zip bytes and analysis report bytes.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the .zip export will be written.
  • output_analysis_report Optional[str] - The output file path where the XML analysis report will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

Tuple[Optional[bytes], Optional[bytes]]: A tuple of (export_file_bytes, analysis_report_bytes).

export_and_analyse_directory

def export_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory using export and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to process.
  • output_directory Optional[str] - The output directory for exported .zip files.
  • analysis_directory Optional[str] - The output directory for XML analysis reports.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • result_dict dict - A dictionary mapping relative file paths to tuples of (export_file_bytes, analysis_report_bytes).

register_import

def register_import(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])

Registers a .zip file to be imported for the given session. The constructed file will be created during the session's run_session call.

Arguments:

  • session int - The session integer.
  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input import file path or bytes.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attribute 'status' indicating the result of the function call. If output_file is None (memory mode), 'buffer', and 'buffer_length' are included containing the file content and file size.

import_file

def import_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Import a .zip file, constructs a file from the .zip file and returns the file bytes. The file is written to output_file if it is provided.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The .zip input file path or bytes.
  • output_file Optional[str] - The output file path where the constructed file will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • file_bytes bytes - The imported file bytes.

import_directory

def import_directory(
input_directory: str,
output_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Imports all files in a directory and its subdirectories. Files are expected as .zip but this is not forced. The constructed files are written to output_directory maintaining the same directory structure as input_directory.

Arguments:

  • input_directory str - The input directory containing files to import.
  • output_directory Optional[str] - The output directory where the constructed files will be written, or None to not write files.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - Default None (sanitise). The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • import_files_dict dict - A dictionary of file paths relative to input_directory, and file bytes.

import_and_analyse_file

def import_and_analyse_file(
input_file: Union[str, bytes, bytearray, io.BytesIO],
output_file: Optional[str] = None,
output_analysis_report: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Imports and analyses a file in a single session, returning both imported file bytes and analysis report bytes.

Arguments:

  • input_file Union[str, bytes, bytearray, io.BytesIO] - The input file path or bytes.
  • output_file Optional[str] - The output file path where the imported file will be written.
  • output_analysis_report Optional[str] - The output file path where the XML analysis report will be written.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply to the session.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

Tuple[Optional[bytes], Optional[bytes]]: A tuple of (import_file_bytes, analysis_report_bytes).

import_and_analyse_directory

def import_and_analyse_directory(
input_directory: str,
output_directory: Optional[str] = None,
analysis_directory: Optional[str] = None,
content_management_policy: Union[
None, str, bytes, bytearray, io.BytesIO,
"glasswall.content_management.policies.policy.Policy"] = None,
raise_unsupported: bool = True)

Recursively processes all files in a directory using import and analyse mode with the given content management policy. Outputs are written to output_directory and analysis_directory maintaining the same structure as input_directory.

Arguments:

  • input_directory str - The input directory containing export .zip files to process.
  • output_directory Optional[str] - The output directory for imported files.
  • analysis_directory Optional[str] - The output directory for XML analysis reports.
  • content_management_policy Union[None, str, bytes, bytearray, io.BytesIO, glasswall.content_management.policies.policy.Policy], optional - The content management policy to apply.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • result_dict dict - A dictionary mapping relative file paths to tuples of (import_file_bytes, analysis_report_bytes).

file_error_message

@functools.lru_cache()
def file_error_message(session: int) -> str

Retrieve the Glasswall Session Process error message.

Arguments:

  • session int - The session integer.

Returns:

  • error_message str - The Glasswall Session Process error message.

GW2GetFileType

def GW2GetFileType(session: int, file_type_id)

Retrieve the file type as a string.

Arguments:

  • session int - The session integer.
  • file_type_id int - The file type id.

Returns:

  • file_type str - The formal file name for the corresponding file id.

GW2GetFileTypeID

def GW2GetFileTypeID(session: int, file_type_str)

Retrieve the Glasswall file type id given a file type string.

Arguments:

  • session int - The session integer.
  • file_type_str str - The file type as a string.

Returns:

  • file_type_id str - The Glasswall file type id for the specified file type.

get_file_type_info

def get_file_type_info(file_type: Union[str, int])

Retrieve information about a file type based on its identifier.

Arguments:

  • file_type Union[str, int] - The file type identifier. This can be either a string representing a file extension (e.g. 'bmp') or an integer corresponding to a file type (e.g. 29).

Returns:

  • file_type_info (Union[int, str]): Depending on the input 'file_type':
  • If file_type is a string (e.g. 'bmp'):
  • If the file type is recognised, returns an integer corresponding to that file type.
  • If the file type is not recognised, returns 0.
  • If file_type is an integer (e.g. 29):
  • If the integer corresponds to a recognised file type, returns a more detailed string description of the file type (e.g. 'BMP Image').
  • If the integer does not match any recognised file type, returns an empty string.

get_file_info

@utils.deprecated_function(replacement_function=get_file_type_info)
def get_file_info(*args, **kwargs)

Deprecated in 1.0.6. Use get_file_type_info.

register_report_file

def register_report_file(session: int, output_file: str)

Register the report file path for the given session.

Arguments:

  • session int - The session integer.
  • output_file str - The file path of the report file.

Returns:

  • gw_return_object glasswall.GwReturnObj - A GwReturnObj instance with the attributes 'session', 'output_file', 'status'.

get_id_info

def get_id_info(issue_id: int, raise_unsupported: bool = True)

Retrieves the group description for the given Issue ID. e.g. issue_id 96 returns "Document Processing Instances"

Arguments:

  • issue_id int - The issue id.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • id_info str - The group description for the given Issue ID.

get_all_id_info

def get_all_id_info(output_file: Optional[str] = None,
raise_unsupported: bool = True) -> str

Retrieves the XML containing all the Issue ID ranges with their group descriptions

Arguments:

  • output_file Optional[str] - The output file path where the analysis file will be written.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

  • all_id_info str - A string XML analysis report containing all id info.

file_session_status_message

def file_session_status_message(session: int,
raise_unsupported: bool = True) -> str

Retrieves the Glasswall session status message. Gives a high level indication of the processing that was carried out.

Arguments:

  • session int - The session integer.
  • raise_unsupported bool, optional - Default True. Raise exceptions when Glasswall encounters an error. Fail silently if False.

Returns:

result.message (str):The file session status message.

licence_details

def licence_details()

Returns a string containing details of the licence.

Returns:

  • result str - A string containing details of the licence.

register_licence

def register_licence(session: int, input_file: Union[str, bytes, bytearray,
io.BytesIO])

Registers a "gwkey.lic" licence from file path or memory.

Arguments:

  • session int - The session integer.
  • input_file Union[str, bytes, bytearray, io.BytesIO] - The "gwkey.lic" licence. It can be provided as a file path (str), bytes, bytearray, or a BytesIO object.

Returns:

  • result (glasswall.GwReturnObj): Depending on the input 'input_file':

  • If input_file is a str file path:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'input_file', 'status'.

  • If input_file is a file in memory:

  • gw_return_object (glasswall.GwReturnObj): A GwReturnObj instance with the attributes 'session', 'buffer', 'buffer_length', 'status'.

EditorError

class EditorError(Exception)

Base class for all Glasswall Editor errors.

EditorSuccess

class EditorSuccess()

Base class for all Glasswall Editor successes.